Navigation

  • index
  • next |
  • previous |
  • PyHowTo documentation »
  • Basic »
  • String »

Table of Contents

Python v3.7 HowTos:

  • ----------------
  • Recursion
  • Backtracking
  • Dynamic Programming
  • Greedy
  • Sort
  • Binary Search
  • Depth First Search [DFS]
  • Breadth First Search [BFS]
  • Binary Search Tree [BST]
  • ----------------
  • Array
  • String
  • Heap
  • Stack
  • Queue
  • Tree
  • Linked List
  • Hash Table
  • Bit Manipulation
  • Two Pointers
  • Math
  • Decorator
  • ----------------
  • Basic
  • Intermediate
  • Advanced
  • Interview
  • ----------------
  • Spark
  • Tkinter
  • Turtle
  • Games
  • Web
  • ----------------
  • About
  • History

Previous topic

Print floating numbers with no decimal places

Next topic

Print integers with ‘*’ on the right

Quick search

Print integers with zeros on the left¶

Print the following integers with zeros on the left of specified width.
x = 3
y = 123

print("\nOriginal Number: ", x)
print("Formatted Number(left padding, width 2): "+"{:0>2d}".format(x));
print("Original Number: ", y)
print("Formatted Number(left padding, width 6): "+"{:0>6d}".format(y));
print()

Output:

Original Number:  3
Formatted Number(left padding, width 2): 03
Original Number:  123
Formatted Number(left padding, width 6): 000123

See also

https://www.w3resource.com/python-exercises/string/python-data-type-string-exercise-33.php

Navigation

  • index
  • next |
  • previous |
  • PyHowTo documentation »
  • Basic »
  • String »
© Copyright 2020, Sergiy Zaytsev, szaytsev@hotmail.com. Created using Sphinx 2.3.0.